﻿namespace BusinessLogic
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using DataAccessLogic;
    using System.Data.SqlClient;
    using System.Web.Security;

    [Serializable]
    public class Address : Table
    {
        #region Fields
        private AddressType _addressType;        
        private string _addressBlock;
        private string _postCode;
        private string _city;
        private State _state;
        private Country _country;
        private bool _isPrimary;
        private bool _isActive;
        #endregion

        #region Methods
        public static Address GetPrimaryByConstituentID(Guid constituentID)
        {
            return AddressDataAccess.GetPrimaryByConstituentID(constituentID);
        }

        public static List<Address> GetAllByConstituentID(Guid constituentID)
        {
            return AddressDataAccess.GetAllByConstituentID(constituentID);            
        }

        public bool CreateForConversion(Guid constituentID)
        {
            try
            {
                this._id = AddressDataAccess.CreateForConversion(this, constituentID);

                if (this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }

            return false;
        }

        public bool Create(Guid constituentID)
        {
            try
            {
                this._id = AddressDataAccess.Create(this, constituentID);

                if (this._id != Guid.Empty)
                {
                    return true;
                }
            }
            catch
            {
                return false;
            }

            return false;
        }

        public void Delete()
        {
            AddressDataAccess.Delete(this.ID);
        }

        public void Update(Guid constituentID)
        {
            AddressDataAccess.Update(this, constituentID);
        }
        #endregion

        #region Properties
        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                _isActive = value;
            }
        }

        public bool IsPrimary
        {
            get
            {
                return _isPrimary;
            }
            set
            {
                _isPrimary = value;
            }
        }

        public AddressType AddressType
        {
            get
            {
                return _addressType;
            }
            set
            {
                _addressType = value;
            }
        }

        public string AddressBlock
        {
            get
            {
                return _addressBlock;
            }
            set
            {
                _addressBlock = value;
            }
        }

        public string City
        {
            get
            {
                return _city;
            }
            set
            {
                _city = value;
            }
        }

        public string PostCode
        {
            get
            {
                return _postCode;
            }
            set
            {
                _postCode = value;
            }
        }

        public State State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }

        public Country Country
        {
            get
            {
                return _country;
            }
            set
            {
                _country = value;
            }
        }
        #endregion
    }
}